<template>
	<div class="app-container">
		<div class="filter-container tw-filter">
			<el-button class="filter-item tw-filter-button" size="medium" icon="el-icon-edit"
				@click="addUserFn()">添加</el-button>
			<el-input v-model="queryList.member_name" placeholder="请输入用户名" class="filter-item tw-filter-input"
				clearable />
			<el-input v-model="queryList.real_name" placeholder="请输入姓名" class="filter-item tw-filter-input" clearable />
			<el-input v-model="queryList.mobile" placeholder="请输入手机号码" class="filter-item tw-filter-input" clearable />
			<el-select v-model="queryList.state" class="filter-item tw-filter-input" placeholder="请选择状态" clearable>
				<el-option key="" label="全部状态" value="" />
				<el-option key="1" label="启用" value="1" />
				<el-option key="0" label="禁用" value="0" />
			</el-select>
			<el-button v-waves class="filter-item tw-filter-button" size="medium" icon="el-icon-search"
				@click="handleFilter">搜索</el-button>			
		</div>

		<el-table v-loading="listLoading" :data="tableList" @selection-change="handleSelectionChange" border fit
			highlight-current-row style="width: 100%;">
			<el-table-column label="ID" prop="id" align="center" width="60" />
			<el-table-column label="用户名" prop="member_name" align="center" />
			<el-table-column label="真实姓名" prop="real_name" align="left" />
			<el-table-column label="手机号码" prop="mobile" align="left" />
			<el-table-column label="注册时间" align="center">
				<template slot-scope="{row}">
					<span>{{ row.add_time | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="状态" align="center">
				<template slot-scope="{row}">
					<span v-if="row.state == 1">启用</span>
					<span v-else>禁用</span>
				</template>
			</el-table-column>

			<el-table-column label="操作" align="center" width="220" class-name="small-padding fixed-width">
				<template slot-scope="{row}">					
					<el-button size="mini" @click="editInfoFn(row)">编辑</el-button>					
					<el-button size="mini" v-has="$store.state.user.btn_common+'del'" type='danger'
						@click="handleDelete(row.id)">删除</el-button>
					
					
				</template>
			</el-table-column>
		</el-table>
		<pagination v-show="isPage && listTotal > 0" :total="listTotal" :page.sync="queryList.curpage"
			:limit.sync="queryList.page" @pagination="getList" />
		<!-- 审核弹窗 -->
		<el-dialog title="审核入会申请" :visible.sync="auditDialogVisible" width="50%" @close="closeAuditDialog">
			<!-- 个人信息部分 -->
			<h3>个人信息</h3>
			<el-row :gutter="20">
				<el-col :span="8"><strong>姓名：</strong></el-col>
				<el-col :span="16">{{ currentAuditRow.real_name }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>性别：</strong></el-col>
				<el-col :span="16">{{ currentAuditRow.sex==1?'男':(currentAuditRow.sex==2?'女':'保密')}}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>民族：</strong></el-col>
				<el-col :span="16">{{ currentAuditRow.nation }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>出生年月：</strong></el-col>
				<el-col :span="16">{{ currentAuditRow.birthday }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>籍贯：</strong></el-col>
				<el-col :span="16">{{ currentAuditRow.native }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>身份证号：</strong></el-col>
				<el-col :span="16">{{ currentAuditRow.idcard }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>手机号：</strong></el-col>
				<el-col :span="16">{{ currentAuditRow.mobile }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>政治面貌：</strong></el-col>
				<el-col :span="16">{{ currentAuditRow.politics }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>学历：</strong></el-col>
				<el-col :span="16">{{ currentAuditRow.education }}</el-col>
			</el-row>

			<div v-if="companyInfo && companyInfo.memberDetail">
				<el-row :gutter="20">
					<el-col :span="8"><strong>工商联职位：</strong></el-col>
					<el-col :span="16">{{ companyInfo.memberDetail.gongshanglianJob }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>人大职位：</strong></el-col>
					<el-col :span="16">{{ companyInfo.memberDetail.rendaJob }}</el-col>
				</el-row>
				<el-row :gutter="20">
					<el-col :span="8"><strong>政协职位：</strong></el-col>
					<el-col :span="16">{{ companyInfo.memberDetail.zhengxeiJob || '无' }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>其他主要社会职务：</strong></el-col>
					<el-col :span="16">{{ companyInfo.memberDetail.qitaJob || '无' }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>本人简历：</strong></el-col>
					<el-col :span="16">{{ companyInfo.memberDetail.benrenJob || '无' }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>其他主要荣誉：</strong></el-col>
					<el-col :span="16">{{ companyInfo.memberDetail.qitaHonor || '无' }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>项目内容：</strong></el-col>
					<el-col :span="16">{{ companyInfo.memberDetail.xiamuInfo || '无' }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>实际捐款捐物金额(万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.memberDetail.shijiMoney || '无' }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>证明人单位、姓名：</strong></el-col>
					<el-col :span="16">{{ companyInfo.memberDetail.zhengmingrenInfo || '无' }}</el-col>
				</el-row>
			</div>

			<el-divider></el-divider>

			<!-- 企业信息部分 -->
			<h3>企业信息</h3>
			<el-row :gutter="20">
				<el-col :span="8"><strong>工商登记名称：</strong></el-col>
				<el-col :span="16">{{ companyInfo.name }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>职位：</strong></el-col>
				<el-col :span="16">{{ companyInfo.position }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>工商注册类型：</strong></el-col>
				<el-col :span="16">{{ companyInfo.customer_type }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>企业代码类型：</strong></el-col>
				<el-col :span="16">{{ companyInfo.customer_credit_type }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>企业代码号：</strong></el-col>
				<el-col :span="16">{{ companyInfo.customer_credit_code }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>行业分类：</strong></el-col>
				<el-col :span="16">{{ companyInfo.classification }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>所在行政区域：</strong></el-col>
				<el-col :span="16">{{ companyInfo.administrative }}</el-col>
			</el-row>
			<el-row :gutter="20">
				<el-col :span="8"><strong>通讯地址：</strong></el-col>
				<el-col :span="16">{{ companyInfo.contact_address }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>企业规模：</strong></el-col>
				<el-col :span="16">{{ companyInfo.scale }}</el-col>
			</el-row>
			<el-row :gutter="20">
				<el-col :span="8"><strong>电话(传真)：</strong></el-col>
				<el-col :span="16">{{ companyInfo.contacts_phone }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>职工总人数：</strong></el-col>
				<el-col :span="16">{{ companyInfo.staff_number }}</el-col>
			</el-row>

			<el-row :gutter="20">
				<el-col :span="8"><strong>营业执照：</strong></el-col>
				<el-col :span="16">
					<img :src="companyInfo.business_license" alt="营业执照" style="width: 200px; height: auto;">
				</el-col>
			</el-row>

			<div v-if="companyInfo && companyInfo.companyDetail">
				<!-- 企业主要社会荣誉 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>企业主要社会荣誉：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.qiyezhuyaoshehuiroyu }}</el-col>
				</el-row>

				<!-- 主营业务 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>主营业务：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.zhuyingyewu }}</el-col>
				</el-row>

				<!-- 主要产品及服务 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>主要产品及服务：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.zhuyaochangpin }}</el-col>
				</el-row>

				<!-- 注册资金 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>注册资金 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.zhuceMoney }}</el-col>
				</el-row>

				<!-- 总资产 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>总资产 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.zongzichangMoney }}</el-col>
				</el-row>

				<!-- 净资产 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>净资产 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.jingzichangMoney }}</el-col>
				</el-row>

				<!-- 资产负债率 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>资产负债率 (%)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.zichangfuzailv }}</el-col>
				</el-row>

				<!-- 近三年经营状况营业收入 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>当年营业收入 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.dangnianMoney }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>上一年营业收入 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shangyinianMoney }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>上两年营业收入 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shanglianianMoney }}</el-col>
				</el-row>

				<!-- 利润总额 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>当年利润总额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.dangnianlirunMoney }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>上一年利润总额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shangyinianlirunMoney }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>上两年利润总额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shanglianianlirunMoney }}</el-col>
				</el-row>

				<!-- 纳税额 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>当年纳税额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.dangniannashuier }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>上一年纳税额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shangyiniannashuier }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>上两年纳税额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shanglianiannashuier }}</el-col>
				</el-row>

				<!-- 技术创新研发中心数量 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>国家级技术创新研发中心数量：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.guojiajiNum }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>省级技术创新研发中心数量：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shengjiNum }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>市县级技术创新研发中心数量：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shixianjiNum }}</el-col>
				</el-row>

				<!-- 科技进步奖数量 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>国家级科技进步奖数量：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.chuanxinguojiajiNum }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>省级科技进步奖数量：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.chuanxingshenghjiNum }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>市县级科技进步奖数量：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.chuanxingshixianjiNum }}</el-col>
				</el-row>

				<!-- 高新技术企业 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>是否被认定为高新技术企业：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.gaoxinqiyeRadio }}</el-col>
				</el-row>

				<!-- 发明专利数量 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>发明专利数量：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.famingNum }}</el-col>
				</el-row>

				<!-- 研发费用占销售收入比例 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>研发费用占销售收入比例 (%)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.yanfaMoney }}</el-col>
				</el-row>

				<!-- 职工劳动合同签订率 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>职工劳动合同签订率 (%)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.zhigomghetongqiandinlv }}</el-col>
				</el-row>

				<!-- 企业签订集体合同情况 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>企业签订集体合同情况：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.zhigomghetongRidio }}</el-col>
				</el-row>

				<!-- 党团工会组织情况 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>是否建立党组织：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.jianlidanzhuzhiRidio }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>是否建立团组织：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.tunzhuzhiRidio }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>是否建立工会组织：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.gonguizhuzhiRidio }}</el-col>
				</el-row>

				<!-- 保险情况 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>参加养老保险人数：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.yanglaobaoxieNum }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>养老保险应缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.yanglaobaoxieyingjiaoMoney }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>养老保险实缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.yanglaobaoxieshijiaoMoney }}</el-col>
				</el-row>

				<!-- 失业保险 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>参加失业保险人数：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shiyebaoxieNum }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>失业保险应缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shiyebaoxieyingjiaoMoney }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>失业保险实缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shiyebaoxieshijiaoMpney }}</el-col>
				</el-row>

				<!-- 参加医疗保险人数 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>参加医疗保险人数：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.yiliaobaoxeiNum }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>医疗保险应缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.yiliaobaoxeiyingjiaoMoney }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>医疗保险实缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.yiliaobaoxeishijiaoMoney }}</el-col>
				</el-row>

				<!-- 参加工伤保险人数 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>参加工伤保险人数：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.gongshangbaoxieNum }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>工伤保险应缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.gongshangbaoxieyingjiaoMoney }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>工伤保险实缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.gongshangbaoxieshijiaoMoney }}</el-col>
				</el-row>

				<!-- 参加生育保险人数 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>参加生育保险人数：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shengyubaoxieNum }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>生育保险应缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shengyubaoxieyingjiaoMoney }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>生育保险实缴额 (万元)：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.shengyubaoxieshijiaoMoney }}</el-col>
				</el-row>

				<!-- 安全生产情况 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>安全生产情况：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.anquanshengchangqingkuang }}</el-col>
				</el-row>

				<!-- 环境保护状况 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>环境保护状况：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.huanjingbaohuqingkuang }}</el-col>
				</el-row>

				<!-- 劳动关系状况 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>劳动关系状况：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.laodongguanxizhuangkuang }}</el-col>
				</el-row>

				<!-- 诚信守法状况 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>诚信守法状况：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.chengxinshoufazhuangkuang }}</el-col>
				</el-row>

				<!-- 纳税信用级别 -->
				<el-row :gutter="20">
					<el-col :span="8"><strong>是否有纳税信用级别：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.is_nashuixingyongjibie }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>最近两年的纳税信用级别年度：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.nashuixingyongjibieniandu }}</el-col>
				</el-row>

				<el-row :gutter="20">
					<el-col :span="8"><strong>最近两年的纳税信用级别：</strong></el-col>
					<el-col :span="16">{{ companyInfo.companyDetail.nashuixingyongjibieNum }}</el-col>
				</el-row>

			</div>

			<el-divider></el-divider>

			<span slot="footer" class="dialog-footer">
				<el-button @click="closeAuditDialog">取消</el-button>
				<el-button type="primary" :loading="auditLoading" @click="confirmAudit">确定</el-button>
			</span>
		</el-dialog>

		<!-- 添加用户 -->
		<el-dialog :title="adduserTitle" :visible.sync="adduserShow" width="50%" @closed='closeDialogFn()'>
			<el-form :model="formData" :rules="rules" ref="ruleForm" label-width="200px" class="demo-ruleForm">
				<el-form-item label="真实姓名" prop="real_name">
					<el-input v-model="formData.real_name"></el-input>
				</el-form-item>
				<el-form-item label="手机号码" prop="mobile">
					<el-input v-model="formData.mobile"></el-input>
				</el-form-item>
				<!-- <el-form-item label="公司" prop='company_id'>
					<el-select v-model="formData.company_id" clearable filterable placeholder="请选择">
						<el-option v-for="item in companyList" :key="item.id" :label="item.name" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="会员的开启状态">
					<template>
						<el-radio v-model="formData.state" label="1">开启</el-radio>
						<el-radio v-model="formData.state" label="0">关闭</el-radio>
					</template>
				</el-form-item>
				<el-form-item label="是否入会">
					<template>
						<el-radio v-model="formData.is_initiation" label="0">未申请</el-radio>
						<el-radio v-model="formData.is_initiation" label="1">已申请</el-radio>
						<el-radio v-model="formData.is_initiation" label="2">已通过</el-radio>
					</template>
				</el-form-item> -->
			</el-form>
			<span slot="footer" class="dialog-footer">
				<div>
					<el-button @click="adduserShow = false">取 消</el-button>
					<el-button @click="saveuserFn('ruleForm')" v-if='num==0'>确 定</el-button>
					<el-button @click="edituserFn('ruleForm')" v-else-if='num==1'>提 交</el-button>
				</div>
			</span>
		</el-dialog>



	</div>
</template>

<script>
	import Pagination from '@/components/Pagination' // 基于el分页的二次封装
	import waves from '@/directive/waves'
	import {
		companyInfo,
		initiationAudit
	} from "@/api/common/common"; // waves directive

	export default {
		components: {
			Pagination
		},
		directives: {
			waves
		},
		data() {
			return {
				auditLoading: true,
				// 数据列表
				listLoading: true,
				listTotal: 0,
				isPage: false,
				tableList: [],
				multipleSelection: [], // 多选数据
				// 添加/编辑弹窗
				dialogFormVisible: false,
				dialogStatus: '',
				textMap: {
					update: '编辑',
					create: '添加'
				},
				//键字段
				keyName: 'id',
				apiPath: 'member.member',

				// 搜索数据
				queryList: {
					page: this.$store.state.settings.page, // 每页显示数量
					curpage: 1, // 当前页码
					member_name: '', //用户名
					real_name: '', //真实姓名
					mobile: '', //手机号码
					state: null // 状态
				},

				// 审核弹窗控制
				auditDialogVisible: false,
				currentAuditRow: {}, // 当前正在审核的行数据
				companyInfo: {
					memberDetail: {},
					companyDetail: {}
				}, // 当前正在审核的公司数据
				adduserShow: false, //添加用户
				formData: {
					real_name: '', //真实姓名
					mobile: '', //手机号码
					state: '1', //会员的开启状态 1为开启 0为关闭
					company_id: '', //公司ID
					is_initiation: '0' //是否入会 0未申请 1已申请 2已通过 已入会

				},
				rules: {
					real_name: [{
						required: true,
						message: '请输入真实名字',
						trigger: 'blur'
					}, ],
					mobile: [{
							required: true,
							message: "请输入手机号",
							trigger: 'blur'
						},
						{
							pattern: /^1[3-9]\d{9}$/,
							message: '请输入正确的手机号码',
							trigger: 'blur',
						}
					],
					company_id: [{
						required: true,
						message: '请选择公司',
						trigger: 'change'
					}],
				},
				companyapiPath: 'operate.company', //公司apiPath
				// 公司搜索数据
				companyQueryList: {
					page: 99999, // 每页显示数量
					curpage: 1, // 当前页码
					name: '',
					customer_legal_representative: '',
					contacts_phone: '',
					is_gq: null,
				},
				companyList: [], //公司列表
				addUserapiPath: 'member.member',
				num: 0,
				userid:'',//用户id
				adduserTitle:'添加'

			}
		},
		created() {
			//获取数据列表
			this.getList();
			//获取公司列表
			this.getCompanyList();
		},
		methods: {
			closeDialogFn(){
				    this.formData.real_name =  ''; //真实姓名
					this.formData.mobile =  '';//手机号码
					this.formData.state = ''; //会员的开启状态 1为开启 0为关闭
					this.formData.company_id =''; //公司ID
					this.formData.is_initiation = ''; //是否入会 0未申请 1已申请 2已通过 已入会
				    this.num = 0;
			},
			getCompanyList() {
				this.$api.fetchList(this.companyQueryList, this.companyapiPath).then(response => {
					let arr = [];
					arr = response.list;
					this.companyList = arr.map(item => {
						return {
							id: item.id,
							name: item.name
						}
					});
					//console.log(this.companyList)

				});
			},
			//添加用户
			addUserFn() {
				this.$nextTick(() => { //清空表单验证的数据
					if (this.$refs.ruleForm) {
						this.$refs.ruleForm.resetFields();
					}
				});
				this.formData = {};
				this.adduserShow = true;
			},
			//保存用户
			saveuserFn(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						this.$api.add(this.formData, this.addUserapiPath).then(() => {
							// 重新获取列表
							this.queryList.curpage = 1
							this.tableList = [];
							this.getList();
							this.adduserShow = false
							this.$message({
								message: '添加成功',
								type: 'success'
							})
						});
					} else {
						return false;
					}
				});
			},
			//编辑用户
			editInfoFn(row) {
				this.$nextTick(() => { //清空表单验证的数据
					if (this.$refs.ruleForm) {
						this.$refs.ruleForm.resetFields();
					}
				});
				//console.log(row)
				this.formData = {};
				let rowCopy  = {...row};
				this.formData = rowCopy;
				this.adduserTitle = '编辑';
				this.num = 1;
				this.formData.real_name = rowCopy.real_name; //真实姓名
				this.formData.mobile = rowCopy.mobile; //手机号码
				this.formData.state = String(rowCopy.state); //会员的开启状态 1为开启 0为关闭
				if(rowCopy.company_id !=0){
					this.formData.company_id = rowCopy.company_id; //公司ID
				}				
				this.formData.is_initiation = String(rowCopy.is_initiation); //是否入会 0未申请 1已申请 2已通过 已入会
				this.userid = rowCopy.id;								 
				this.adduserShow = true;
			},
			edituserFn(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						let data = {
							...this.formData,
							id:this.userid
						}
						//console.log(data)
						this.$api.edit(data, this.addUserapiPath).then(() => {							// 重新获取列表
							this.queryList.curpage = 1
							this.tableList = [];
							this.getList();
							this.adduserShow = false
							this.$message({
								message: '修改成功',
								type: 'success'
							})
						});
					} else {
						return false;
					}
				});
			},
			// 打开审核弹窗
			openAuditDialog(row) {
				//console.log(row)
				companyInfo({
					company_id: row.company_id
				}, this.apiPath).then((res) => {
					this.companyInfo = res;
				});
				this.currentAuditRow = row;
				this.auditDialogVisible = true;
			},

			// 关闭审核弹窗
			closeAuditDialog() {
				this.auditDialogVisible = false;
				this.currentAuditRow = {};
			},

			// 确认审核入会申请
			confirmAudit() {
				if (!this.currentAuditRow || !this.currentAuditRow.id) {
					this.$message.error('审核信息不完整');
					return;
				}

				// 禁用按钮避免重复提交
				this.auditLoading = true;
				this.$confirm('确认删除数据吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$api.del({
						id_str: id_str
					}, this.apiPath).then(response => {
						this.getList();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
					});
				});
				if (this.currentAuditRow.is_initiation == 1) {
					this.$confirm('确认通过该审核吗?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						initiationAudit({
								id_str: this.currentAuditRow.id
							}, this.apiPath)
							.then(() => {
								this.$message({
									message: '审核通过成功',
									type: 'success',
								});

								// 刷新列表
								this.getList();
								this.closeAuditDialog();
							})
							.catch((error) => {
								// 错误处理
								this.$message.error('审核失败: ' + error.message);
							})
							.finally(() => {
								// 恢复按钮状态
								this.auditLoading = false;
							});
					});
				}
			},


			// 搜索
			handleFilter() {
				this.queryList.curpage = 1;
				this.tableList = [];
				this.listTotal = 0;
				this.getList();
			},

			// 列表选择
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},

			// 获取数据列表
			getList() {
				this.listLoading = true;
				this.$api.fetchList(this.queryList, this.apiPath).then(response => {
					this.tableList = response.list;
					this.listTotal = response.list_count;
					this.isPage = response.is_page;
					this.listLoading = false;
				});
			},

			// 删除
			handleDelete(id = 0) {
				let current = this;
				let id_str = '';
				if (!id) {
					if (!this.multipleSelection.length) {
						this.$message({
							message: '请选择删除的条目！',
							type: 'warning'
						});
						return false;
					}
					this.multipleSelection.forEach(item => {
						id_str += item[current.keyName] + ',';
					});
				} else {
					id_str = id;
				}

				this.$confirm('确认删除数据吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$api.del({
						id_str: id_str
					}, this.apiPath).then(response => {
						this.getList();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
					});
				});
			}
			
		}
	}
</script>
<style>
	.active-button {
		color: #409EFF;
		/* 蓝色 */
		cursor: pointer;
	}

	.disabled-button {
		color: #c0c4cc;
		/* 灰色 */
		cursor: not-allowed;
	}

	.el-dialog__body {
		padding: 20px;
	}

	.el-row {
		margin-bottom: 10px;
	}

	.el-col {
		line-height: 28px;
	}

	h3 {
		font-size: 16px;
		font-weight: bold;
		margin-top: 20px;
		margin-bottom: 10px;
	}
</style>